//
//  SingelProductCellTwo.m
//  FlyGift
//
//  Created by lanou3g on 15/7/12.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "SingleProductCellTwo.h"

@interface SingleProductCellTwo ()
{
    CGFloat width;
    CGFloat height;
}

@end

@implementation SingleProductCellTwo



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        width = self.frame.size.width;
        height = self.frame.size.height - width;
        // 产品图片
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.width)];
        self.imageView.image = [UIImage imageNamed:@"placeHolder@2x.jpg"];
        [self.contentView addSubview:_imageView];
        // 收藏图片和数目后面的阴影
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(width / 20, width / 20, width * 2 / 5, width / 12)];
        view.backgroundColor = [UIColor colorWithWhite:0.237 alpha:0.3];
        [view.layer setCornerRadius:5];
        [self.contentView addSubview:view];
        // 收藏图片
        self.collectBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        self.collectBtn.frame = CGRectMake(width / 20, width / 20, width / 12, width / 12);
        [self.contentView addSubview:_collectBtn];
        // 收藏数目
        self.collectLabel = [[UILabel alloc]initWithFrame:CGRectMake(width / 6, width / 20, width / 3, width / 12)];
        self.collectLabel.textColor = [UIColor redColor];
        self.collectLabel.font = [UIFont systemFontOfSize:width / 12];
        [self.contentView addSubview:_collectLabel];
        // 价格
        self.priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(width / 20, width, width / 2, height / 3)];
        self.priceLabel.font = [UIFont systemFontOfSize:height / 5];
        self.priceLabel.textColor = [UIColor colorWithRed:1.000 green:0.080 blue:0.000 alpha:1.000];
        [self.contentView addSubview:_priceLabel];
        // 产品名称
        self.title = [[UILabel alloc]initWithFrame:CGRectZero];
        self.title.numberOfLines = 0;
        self.title.font = [UIFont fontWithName:@"CourierNewPS-ItalicMT" size:height / 4];
        self.title.textColor = [UIColor blackColor];
        [self.contentView addSubview:_title];
    }
    return self;
}

// 设置单品cell上的内容
- (void)setItemValueWithModel:(SingleProductModel *)model
{
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url] placeholderImage:[UIImage imageNamed:@"placeHolder@2x.jpg"]];
    self.title.text = model.name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
    self.collectLabel.text = model.favorites_count.stringValue;
    if (model.isClick) {
        [self.collectBtn setBackgroundImage:[UIImage imageNamed:@"shoucang2"] forState:UIControlStateNormal];
    }else
    {
        [self.collectBtn setBackgroundImage:[UIImage imageNamed:@"shoucang1"] forState:UIControlStateNormal];
    }
    CGRect bounds = [self.title.text boundingRectWithSize:CGSizeMake(width - width / 20, height * 2 / 3) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:height / 4] forKey:NSFontAttributeName] context:nil];
    self.title.font = [UIFont systemFontOfSize:height / 4];
    self.title.frame = CGRectMake(width / 20, width + height / 3, width - width / 20, bounds.size.height);
}

// 设置品牌页面上cell上的内容
- (void)setBrandHomeItemValueWithModel:(BrandHomeModel *)model
{
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url] placeholderImage:[UIImage imageNamed:@"placeHolder@2x.jpg"]];
    self.title.text = model.name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
    self.collectLabel.text = model.favorites_count.stringValue;
    if (model.isClick) {
        [self.collectBtn setBackgroundImage:[UIImage imageNamed:@"shoucang2"] forState:UIControlStateNormal];
    }else
    {
        [self.collectBtn setBackgroundImage:[UIImage imageNamed:@"shoucang1"] forState:UIControlStateNormal];
    }
    CGRect bounds = [self.title.text boundingRectWithSize:CGSizeMake(width - width / 20, height * 2 / 3) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:height / 4 - 2] forKey:NSFontAttributeName] context:nil];
    self.title.font = [UIFont systemFontOfSize:height / 4 - 2];
    self.title.frame = CGRectMake(width / 20, width + height / 3, width - width / 20, bounds.size.height);
}

@end
